<template>
  <div class="ele-body">
    <el-row :gutter="15">
      <el-col :md="6" :sm="8">

      </el-col>
      <el-col :md="18" :sm="16">
        <el-card shadow="never" body-style="padding-top: 5px;">
          <el-tabs v-model="active" class="user-info-tabs">
            <el-tab-pane label="基本信息" name="info">
              <el-form
                ref="infoForm"
                :model="form"
                :rules="rules"
                label-width="150px"
                style="max-width: 550px;padding-top: 40px;"
                @keyup.enter.native="save"
                @submit.native.prevent>
                <el-form-item label="门店名称:" prop="room_name">
                  <el-input
                    v-model="form.room_name"
                    placeholder="门店名称"
                    clearable/>
                </el-form-item>
                <el-form-item label="门店logo图:">
                  <uploadImage :limit="1" v-model="form.head_url"></uploadImage>
                </el-form-item>
                <el-form-item label="2微码图片:">

                  <uploadImage :limit="0" v-model="form.code_image_url"
                               @click="downImg(form.code_image_url)"></uploadImage>

                </el-form-item>
                <el-form-item label="门店轮播图:">
                  <uploadImage :limit="5" v-model="form.make_image"></uploadImage>
                </el-form-item>
                <el-form-item
                  label="负责人名称:"
                  prop="name">
                  <el-input
                    :maxlength="20"
                    v-model="form.name"

                    clearable/>
                </el-form-item>

                <el-form-item
                  label="联系电话:"
                  prop="mobile">
                  <el-input
                    :maxlength="20"
                    v-model="form.mobile"
                    placeholder="请输入联系电话"
                    clearable/>
                </el-form-item>
                <el-form-item label="发布状态:">
                  <el-radio-group
                    v-model="form.status">
                    <el-radio :label="1">营业中</el-radio>
                    <el-radio :label="2">装修中</el-radio>
                    <el-radio :label="3">筹备中</el-radio>
                  </el-radio-group>
                </el-form-item>
                <el-form-item
                  label="保洁打扫时间(分钟):"
                  prop="time">
                  <el-input
                    :maxlength="20"
                    v-model="form.time"
                    placeholder="请输入保洁打扫时间"
                    clearable/>
                </el-form-item>
                <el-form-item label="所在城市:" prop="city">
                  <el-cascader
                    clearable
                    v-model="city"
                    class="ele-fluid"
                    placeholder="请选择省市区"
                    :options="regions.cityData"
                    popper-class="ele-pop-wrap-higher"/>
                </el-form-item>

                <el-form-item
                  label="详细地址:"
                  prop="address">
                  <el-input
                    :maxlength="20"
                    v-model="form.address"
                    placeholder="请输入详细地址"
                    clearable/>
                </el-form-item>


                <el-form-item
                  label="地址:"
                  prop="address">
                  <el-input
                    disabled="disabled"
                    :maxlength="20"
                    v-model="form.address_lan"

                    clearable/>
                </el-form-item>

                <el-row :gutter="15">
                  <el-col :sm="12">
                    <el-form-item label="开始营业:" prop="hours_add_time">
                      <el-select
                        clearable
                        class="ele-block"
                        v-model="form.hours_add_time"
                        placeholder="请选择营业时间">
                        <el-option label="00" :value="0"/>
                        <el-option label="01" :value="1"/>
                        <el-option label="02" :value="2"/>
                        <el-option label="03" :value="3"/>
                        <el-option label="04" :value="4"/>
                        <el-option label="05" :value="5"/>
                        <el-option label="06" :value="6"/>
                        <el-option label="07" :value="7"/>
                        <el-option label="08" :value="8"/>
                        <el-option label="09" :value="9"/>
                        <el-option label="10" :value="10"/>
                        <el-option label="11" :value="11"/>
                        <el-option label="12" :value="12"/>
                        <el-option label="13" :value="13"/>
                        <el-option label="14" :value="14"/>
                        <el-option label="15" :value="15"/>
                        <el-option label="16" :value="16"/>
                        <el-option label="17" :value="17"/>
                        <el-option label="18" :value="18"/>
                        <el-option label="19" :value="19"/>
                        <el-option label="20" :value="20"/>
                        <el-option label="21" :value="21"/>
                        <el-option label="22" :value="22"/>
                        <el-option label="23" :value="23"/>
                      </el-select>
                    </el-form-item>


                    <el-form-item label="结束营业:" prop="hours_end_time">
                      <el-select
                        clearable
                        class="ele-block"
                        v-model="form.hours_end_time"
                        placeholder="请选择营业时间">

                        <el-option label="01" :value="1"/>
                        <el-option label="02" :value="2"/>
                        <el-option label="03" :value="3"/>
                        <el-option label="04" :value="4"/>
                        <el-option label="05" :value="5"/>
                        <el-option label="06" :value="6"/>
                        <el-option label="07" :value="7"/>
                        <el-option label="08" :value="8"/>
                        <el-option label="09" :value="9"/>
                        <el-option label="10" :value="10"/>
                        <el-option label="11" :value="11"/>
                        <el-option label="12" :value="12"/>
                        <el-option label="13" :value="13"/>
                        <el-option label="14" :value="14"/>
                        <el-option label="15" :value="15"/>
                        <el-option label="16" :value="16"/>
                        <el-option label="17" :value="17"/>
                        <el-option label="18" :value="18"/>
                        <el-option label="19" :value="19"/>
                        <el-option label="20" :value="20"/>
                        <el-option label="21" :value="21"/>
                        <el-option label="22" :value="22"/>
                        <el-option label="23" :value="23"/>
                        <el-option label="24" :value="24"/>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :sm="12">
                    <el-form-item prop="hours_add_time_fen">
                      <el-select
                        clearable
                        class="ele-block"
                        v-model="form.hours_add_time_fen"
                        placeholder="请选择营业时间">
                        <el-option label="00" :value="0"/>
                        <el-option label="01" :value="1"/>
                        <el-option label="02" :value="2"/>
                        <el-option label="03" :value="3"/>
                        <el-option label="04" :value="4"/>
                        <el-option label="05" :value="5"/>
                        <el-option label="06" :value="6"/>
                        <el-option label="07" :value="7"/>
                        <el-option label="08" :value="8"/>
                        <el-option label="09" :value="9"/>
                        <el-option label="10" :value="10"/>
                        <el-option label="11" :value="11"/>
                        <el-option label="12" :value="12"/>
                        <el-option label="13" :value="13"/>
                        <el-option label="14" :value="14"/>
                        <el-option label="15" :value="15"/>
                        <el-option label="16" :value="16"/>
                        <el-option label="17" :value="17"/>
                        <el-option label="18" :value="18"/>
                        <el-option label="19" :value="19"/>
                        <el-option label="20" :value="20"/>
                        <el-option label="21" :value="21"/>
                        <el-option label="22" :value="22"/>
                        <el-option label="23" :value="23"/>
                        <el-option label="24" :value="24"/>
                        <el-option label="25" :value="25"/>
                        <el-option label="26" :value="26"/>
                        <el-option label="27" :value="27"/>
                        <el-option label="28" :value="28"/>
                        <el-option label="29" :value="29"/>
                        <el-option label="30" :value="30"/>
                        <el-option label="31" :value="31"/>
                        <el-option label="32" :value="32"/>
                        <el-option label="33" :value="33"/>
                        <el-option label="34" :value="34"/>
                        <el-option label="35" :value="35"/>
                        <el-option label="36" :value="36"/>
                        <el-option label="37" :value="37"/>
                        <el-option label="38" :value="38"/>
                        <el-option label="39" :value="39"/>
                        <el-option label="40" :value="40"/>
                        <el-option label="41" :value="41"/>
                        <el-option label="42" :value="42"/>
                        <el-option label="43" :value="43"/>
                        <el-option label="44" :value="44"/>
                        <el-option label="45" :value="45"/>
                        <el-option label="46" :value="46"/>
                        <el-option label="47" :value="47"/>
                        <el-option label="48" :value="48"/>
                        <el-option label="49" :value="49"/>
                        <el-option label="50" :value="50"/>
                        <el-option label="51" :value="51"/>
                        <el-option label="52" :value="52"/>
                        <el-option label="53" :value="53"/>
                        <el-option label="54" :value="54"/>
                        <el-option label="55" :value="55"/>
                        <el-option label="56" :value="56"/>
                        <el-option label="57" :value="57"/>
                        <el-option label="58" :value="58"/>
                        <el-option label="59" :value="59"/>
                      </el-select>
                    </el-form-item>
                    <el-form-item prop="hours_end_time_fen">
                      <el-select
                        clearable
                        class="ele-block"
                        v-model="form.hours_end_time_fen"
                        placeholder="请选择营业时间">
                        <el-option label="00" :value="0"/>
                        <el-option label="01" :value="1"/>
                        <el-option label="02" :value="2"/>
                        <el-option label="03" :value="3"/>
                        <el-option label="04" :value="4"/>
                        <el-option label="05" :value="5"/>
                        <el-option label="06" :value="6"/>
                        <el-option label="07" :value="7"/>
                        <el-option label="08" :value="8"/>
                        <el-option label="09" :value="9"/>
                        <el-option label="10" :value="10"/>
                        <el-option label="11" :value="11"/>
                        <el-option label="12" :value="12"/>
                        <el-option label="13" :value="13"/>
                        <el-option label="14" :value="14"/>
                        <el-option label="15" :value="15"/>
                        <el-option label="16" :value="16"/>
                        <el-option label="17" :value="17"/>
                        <el-option label="18" :value="18"/>
                        <el-option label="19" :value="19"/>
                        <el-option label="20" :value="20"/>
                        <el-option label="21" :value="21"/>
                        <el-option label="22" :value="22"/>
                        <el-option label="23" :value="23"/>
                        <el-option label="24" :value="24"/>
                        <el-option label="25" :value="25"/>
                        <el-option label="26" :value="26"/>
                        <el-option label="27" :value="27"/>
                        <el-option label="28" :value="28"/>
                        <el-option label="29" :value="29"/>
                        <el-option label="30" :value="30"/>
                        <el-option label="31" :value="31"/>
                        <el-option label="32" :value="32"/>
                        <el-option label="33" :value="33"/>
                        <el-option label="34" :value="34"/>
                        <el-option label="35" :value="35"/>
                        <el-option label="36" :value="36"/>
                        <el-option label="37" :value="37"/>
                        <el-option label="38" :value="38"/>
                        <el-option label="39" :value="39"/>
                        <el-option label="40" :value="40"/>
                        <el-option label="41" :value="41"/>
                        <el-option label="42" :value="42"/>
                        <el-option label="43" :value="43"/>
                        <el-option label="44" :value="44"/>
                        <el-option label="45" :value="45"/>
                        <el-option label="46" :value="46"/>
                        <el-option label="47" :value="47"/>
                        <el-option label="48" :value="48"/>
                        <el-option label="49" :value="49"/>
                        <el-option label="50" :value="50"/>
                        <el-option label="51" :value="51"/>
                        <el-option label="52" :value="52"/>
                        <el-option label="53" :value="53"/>
                        <el-option label="54" :value="54"/>
                        <el-option label="55" :value="55"/>
                        <el-option label="56" :value="56"/>
                        <el-option label="57" :value="57"/>
                        <el-option label="58" :value="58"/>
                        <el-option label="59" :value="59"/>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>

                <el-form-item label="门店简介" prop="brief">
                  <el-input
                    :rows="3"
                    clearable
                    type="textarea"
                    :maxlength="200"
                    v-model="form.brief"
                    placeholder="门店简介"/>
                </el-form-item>

                <el-form-item
                  label="地址:"
                  prop="lat">
                  <el-input
                    :maxlength="20"
                    v-model="form.address_lan"
                    placeholder="地址"
                    clearable/>
                  <a href="https://lbs.qq.com/getPoint/" target="_blank">获取经纬度</a>
                </el-form-item>
                <el-form-item
                  label="经纬度:"
                  prop="lat">
                  <el-input
                    :maxlength="20"
                    v-model="form.lat"
                    placeholder="经纬度"
                    clearable/>
                </el-form-item>
                <el-form-item>
                  <el-button
                    type="primary"
                    @click="save"
                    :loading="loading">保存更改
                  </el-button>
                </el-form-item>
              </el-form>
            </el-tab-pane>

          </el-tabs>
        </el-card>
      </el-col>
    </el-row>


  </div>
</template>

<script>
import setting from '@/config/setting';
import uploadImage from '@/components/uploadImage'
import regions from 'ele-admin/packages/regions';
import TinymceEditor from '@/components/TinymceEditor'
import '@riophae/vue-treeselect/dist/vue-treeselect.css';

export default {
  name: 'UserInfo',

  components: {uploadImage, TinymceEditor},
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object
  },
  data() {
    return {
      active: 'info',
      // 省市区数据
      regions: regions,
      // 选中的省市区
      city: [],
      // 选中的省市
      provinceCity: [],
      // 选中的省
      province: [],
      // 表单数据
      form: Object.assign({status: 1, is_default: 1}, this.data),
      // 表单验证规则
      rules: {

        // city: [
        //     {required: true, message: '请选择省市区', trigger: 'blur'}
        // ]
      },
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false
    };
  },
  watch: {
    data() {
      if (this.data) {
        this.form = Object.assign({}, this.data);
        // 取值赋予城市组件
        this.city = this.data.city;
        this.isUpdate = true;
      } else {
        this.form = {};
        this.isUpdate = false;
        // 清空省市区控件
        this.city = [];
      }
    }
  },
  computed: {

    //初始化地图
    init() {
      //定义map变量 调用 qq.maps.Map() 构造函数   获取地图显示容器
      var map = new qq.maps.Map(document.getElementById("container"), {
        center: new qq.maps.LatLng(39.916527, 116.397128),      // 地图的中心地理坐标。
        zoom: 8                                                 // 地图的中心地理坐标。
      });
    },
    // 初始化富文本
    initEditor() {
      return {
        height: 300,
        branding: false,
        skin_url: '/tinymce/skins/ui/oxide',
        content_css: '/tinymce/skins/content/default/content.css',
        language_url: '/tinymce/langs/zh_CN.js',
        language: 'zh_CN',
        plugins: 'code print preview fullscreen paste searchreplace save autosave link autolink image imagetools media table codesample lists advlist hr charmap emoticons anchor directionality pagebreak quickbars nonbreaking visualblocks visualchars wordcount',
        toolbar: 'fullscreen preview code | undo redo | forecolor backcolor | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | formatselect fontselect fontsizeselect | link image media emoticons charmap anchor pagebreak codesample | ltr rtl',
        toolbar_drawer: 'sliding',
        images_upload_handler: (blobInfo, success, error) => {
          let file = blobInfo.blob();
          // 使用axios上传
          const formData = new FormData();
          formData.append('file', file, file.name);
          this.$http.post('/upload/uploadImage', formData).then(res => {
            if (res.data.code == 0) {
              success(res.data.data);
            } else {
              error(res.data.msg);
            }
          }).catch(e => {
            console.error(e);
            error(e.message);
          });
        },
        file_picker_types: 'media',
        file_picker_callback: () => {
        }
      }
    }
  },
  mounted() {
    // 获取用户信息
    this.getUserInfo();
  },

  methods: {

    /* 获取当前用户信息 */
    getUserInfo() {
      if (setting.userUrl) {
        this.$http.get('/room/getUserInfo').then((res) => {
          const result = setting.parseUser ? setting.parseUser(res.data) : res.data;
          if (result.code === 0) {
            // 赋予对象值
            this.form = JSON.parse(JSON.stringify(result.data))
            this.city = this.form.city;
          } else {
            this.$message.error(result.msg);
          }
        }).catch((e) => {
          console.error(e);
          this.$message.error(e.message);
        });
      }
    },
    downImg(imgsrc) {
      const src = `${imgsrc}?t=${new Date().getTime()}`
      fetch(src).then(res => {
        res.blob().then(myBlob => {
          const href = URL.createObjectURL(myBlob)
          const a = document.createElement('a')
          a.href = href
          a.download = '门店二维码.jpg'
          a.click()
          a.remove()
        })
      })
    },
    /* 保存更改 */
    save() {
      this.$refs['infoForm'].validate((valid) => {
        if (valid) {
          this.loading = true;
          this.form = Object.assign({}, this.form, {
            city: this.city
          });
          this.$http.post('/room/updateUserInfo', this.form).then(res => {
            this.loading = false;
            if (res.data.code === 0) {
              this.$message.success('保存成功');
            } else {
              this.$message.error(res.data.msg);
            }
          }).catch(e => {
            this.loading = false;
            this.$message.error(e.message);
          });
        } else {
          return false;
        }
      });
    },
    /* 更新visible */
    updateVisible(value) {
      this.$emit('update:visible', value);
    }
  }
}
</script>

<style scoped>
.ele-body {
  padding-bottom: 0;
}

.el-card {
  margin-bottom: 15px;
}

/* 用户资料卡片 */
.user-info-card {
  padding-top: 8px;
  text-align: center;
}

.user-info-card .user-info-avatar-group {
  position: relative;
  cursor: pointer;
  margin: 0 auto;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  overflow: hidden;
}

.user-info-card .user-info-avatar {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  object-fit: cover;
}

.user-info-card .user-info-avatar-group > i {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #FFF;
  font-size: 30px;
  display: none;
  z-index: 2;
}

.user-info-card .user-info-avatar-group:hover > i {
  display: block;
}

.user-info-card .user-info-avatar-group:hover:after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, .3);
}

.user-info-card .user-info-name {
  font-size: 24px;
  margin-top: 20px;
}

.user-info-card .user-info-desc {
  margin-top: 8px;
}

/* 用户信息列表 */
.user-info-list {
  margin-top: 30px;
}

.user-info-list .user-info-item {
  margin-bottom: 10px;
  display: flex;
  align-items: baseline;
}

.user-info-item > i {
  margin-right: 10px;
  font-size: 16px;
}

.user-info-item > span {
  flex: 1;
  display: block;
}

/* 用户标签 */
.user-info-tags .el-tag {
  margin: 10px 10px 0 0;
}

/* 用户账号绑定列表 */
.user-account-list {
  margin-top: 10px;
}

.user-account-list .user-account-item {
  padding: 15px;
}

.user-account-list .user-account-item .ele-text-secondary {
  margin-top: 6px;
}

.user-account-list .user-account-item .user-account-icon {
  width: 42px;
  height: 42px;
  line-height: 42px;
  text-align: center;
  color: #FFF;
  font-size: 26px;
  border-radius: 50%;
  background-color: #3492ED;
  box-sizing: border-box;
}

.user-account-list .user-account-item .user-account-icon.el-icon-_wechat {
  background-color: #4DAF29;
  font-size: 28px;
}

.user-account-list .user-account-item .user-account-icon.el-icon-_alipay {
  background-color: #1476FE;
  padding-left: 5px;
  font-size: 32px;
}

/* tab页签 */
.user-info-tabs ::v-deep .el-tabs__nav-wrap {
  padding-left: 20px;
}
</style>
